/*
 * @Author: zhangfeng
 * @Date: 2023-12-20 17:16:18
 * @LastEditTime: 2023-12-20 18:10:49
 * @LastEditors: zhangfeng
 * @Description:
 * @FilePath: \nodeapi\src\middleware\menus.middleware.js
 * © 2023 张峰，All rights reserved.
 */
const { isHasChildServerMenus } = require("../server/menus.server");
const { menuDeleteisParentFormatterError } = require("../constants/err.type");

const isHasChild = async (ctx, next) => {
  try {
    const result = await isHasChildServerMenus(ctx.request.body.id);
    if (result) {
      return (ctx.body = menuDeleteisParentFormatterError);
    }
    await next();
  } catch (error) {
    ctx.body = menuDeleteisParentFormatterError;
    return;
  }
};

module.exports = {
  isHasChild,
};
